<template>
  <view class="container">
    <view class="example">
      <uni-forms ref="form" :model="pigList" labelWidth="80px">
        <uni-forms-item label="猪只耳号" name="pigCode" required>
          <uni-easyinput v-model="pigList.pigCode" placeholder="请输入猪只耳号" />
        </uni-forms-item>
        <uni-forms-item label="所属批次" name="pigBatch">
          <uni-easyinput v-model="pigList.pigBatch" placeholder="请输入所属批次" />
        </uni-forms-item>
		
        <uni-forms-item label="猪只品种" name="pigBreed" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigList.pigBreed"
			 :localdata="pigBreeds" 
			 >
			 </uni-data-select>
        </uni-forms-item>
		<uni-forms-item label="猪只类型" name="pigType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigList.pigType"
			 :localdata="pigTypes" 
			 >
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="猪只状态" name="pigStatus" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigList.pigStatus"
			 :localdata="pigStatuses" 
			 >
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="已产胎次" name="pigNippleLeftNum" required>
		<uni-easyinput type="number" v-model="pigList.pigParity" placeholder="请输入已产胎次(次)" />
		</uni-forms-item>
		<uni-forms-item label="猪只来源" name="pigOrigin" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigList.pigOrigin"
			 :localdata="pigOrigins" 
			>
			 </uni-data-select>
		</uni-forms-item>
		
		
		<view class="example-body">
			<uni-forms-item label="出生时间" name="pigBirthday">
			  <uni-datetime-picker type="datetime" v-model="pigList.pigBirthday"  />
			</uni-forms-item>
		</view>	
		<view class="example-body">
			<uni-forms-item label="入场时间" name="pigBirthday">
			  <uni-datetime-picker type="datetime" v-model="pigList.pigIncomeTime"  />
			</uni-forms-item>
		</view>	
		<uni-forms-item label="栏舍类型" name="phouseType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigList.phouseType"
			 :localdata="phouseTypes" 
			>
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="栏舍编码" name="phouseCode">
			  <uni-easyinput v-model="pigList.phouseCode" placeholder="请输入栏舍编码" />
		</uni-forms-item>
		<uni-forms-item label="出生体重" name="pigBirthWeight" required>
		  <uni-easyinput type="number" v-model="pigList.pigBirthWeight" placeholder="请输入出生重量(kg)" />
		</uni-forms-item>
		<uni-forms-item label="左乳头数" name="pigNippleLeftNum" required>
		  <uni-easyinput type="number" v-model="pigList.pigNippleLeftNum" placeholder="请输入左乳头数(个)" />
		</uni-forms-item>
		<uni-forms-item label="右乳头数" name="materiaFeedPurchaseWeight" required>
		  <uni-easyinput type="number" v-model="pigList.pigNippleRightNum" placeholder="请输入右乳头数(个)" />
		</uni-forms-item>
		<uni-forms-item label="备注">
			<uni-easyinput type="textarea" v-model="pigList.remark" placeholder="请输入备注内容" />
		</uni-forms-item>
      </uni-forms>
      <button type="primary" @click="submit">提交</button>
    </view>
  </view>
</template>

<script>

import { addPig} from "@/api/hmy/pig";


export default {
  name: "Pig",
  data() {
    return {
		pigList: {
			pigCode: "", // 猪只耳号
			pigBatch: "",//所属批次
			pigBreed: "",// 猪只品种
			pigType: "", //猪只类型
			pigBreedTime: "", //出生时间
			pigIncomeTime:"",//入场时间
			phouseType: "",//栏舍类型
			pigStatus:"", //猪只状态
			pigOrigin:'', //猪只来源
			pigBirthWeight:"",//出生体重
			pigNippleLeftNum:"",//左乳头数
			pigNippleRightNum:"",//右乳头数
			remark:"",//备注
		},
		// 猪只品种列表
		pigBreeds: [
			{text: '大白',value: "1"},
			{text: '长白',value: "2"},
			{text: '二元',value: "3"},
			{text: '三元',value: "4"},
		],
		// 猪只类型
		pigTypes:[
			{text: ' 种猪',value: "1"},
			{text: ' 母猪',value: "2"},
			{text: ' 肉猪',value: "3"}
		],
		// 栏舍类型
		phouseTypes:[
			{text: ' 种猪',value: "1"},
			{text: ' 母猪',value: "2"},
			{text: ' 肉猪',value: "3"}
		],
		//猪只状态
		pigStatuses: [
			{text: '未进场',value: "1"},
			{text: '已进场',value: "2"},
			{text: '死亡',value: "3"},
			{text: '生病',value: "4"},
		],
		//
		pigOrigins:[
			{text: '购买',value: "1"},
			{text: '自繁',value: "2"}
		],
		rules: {
		  pigCode: {
			rules: [{
			  required: true,
			  errorMessage: '猪只耳号不能为空'
			}]
		  }
	    }
	}
  },

  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  methods: {
    submit(ref) {
      this.$refs.form.validate().then(res => {
        addPig(this.pigList).then(response => {
          this.$modal.msgSuccess("新增成功")
		  //成功后返回页面
		  this.$tab.navigateTo('/pages/hmy/pig/index');
        })
      })
    }
  }
}
</script>

<style lang="scss">
	
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100%;
    height: auto;
	background-color: #fcfcfc;
  }

  view {
    font-size: 16px;
    line-height: inherit;
  }
  /* #endif */
  .code{
	margin-bottom :5px;
  }
  .icon{
	float:right;
	margin-right:10px;
	margin-top :5px;
  }
  .message{
	margin-top:5px;
	color: #989897;
	line-height: 25px;
  }

  
  .example {
    padding: 15px;
    background-color: #fff;
  }
  
  .segmented-control {
    margin-bottom: 15px;
  }
  
  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }
  
  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }
  
  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
</style>

